#include "TcpService.h"
#include "tcphandle.h"
#include <iostream>


namespace myrpc
{
	namespace mynet
	{

		TcpServer::TcpServer()
		{
			loop_ = uvw::Loop::getDefault();
		}

		int TcpServer::Active(std::string ip, int port)
		{
			listener_.reset(new TcpServer(ip, port));
			listener_->Init(loop_);
			this->Active();
			return 0;
		}

		void TcpServer::Active()
		{
			listener_->SetOnConnect([&](std::shared_ptr<TcpServer> handle)
			{
				this->linklist_.push_back(handle);
			});

			listener_->SetOnRead([&](PackagePtr package)
			{
				//this->packlist_.push_back(package);
				packgereachhandle_(package);
			});
			listener_->Listen();
			loop_->run();

		}
	}
}

